/*===========================================================================+
 |   Copyright (c) 2001, 2005 Oracle Corporation, Redwood Shores, CA, USA    |
 |                         All rights reserved.                              |
 +===========================================================================+
 |  HISTORY                                                                  |
 +===========================================================================*/
package xxhci.oracle.apps.XXIERP.SalaryAdvance.webui;

import java.io.Serializable;


import java.text.DecimalFormat;

import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.OAViewObject;
import oracle.apps.fnd.framework.server.OADBTransaction;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.OAWebBeanConstants;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.fnd.framework.webui.beans.form.OASubmitButtonBean;
import oracle.apps.fnd.framework.webui.beans.layout.OAHeaderBean;


import oracle.apps.fnd.framework.webui.beans.layout.OAMessageComponentLayoutBean;
import oracle.apps.fnd.framework.webui.beans.layout.OARowLayoutBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageDateFieldBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageTextInputBean;

import oracle.apps.fnd.framework.webui.beans.nav.OAPageButtonBarBean;
import oracle.apps.fnd.framework.webui.beans.table.OATableBean;

//import oracle.cabo.style.CSSStyle;


import oracle.jbo.Row;
import oracle.jbo.domain.Date;
import oracle.jbo.domain.Number;
//import java.sql.Date;


import xxhci.oracle.apps.XXIERP.SalaryAdvance.server.EmpVORowImpl;
import xxhci.oracle.apps.XXIERP.SalaryAdvance.server.XxierpSalaryAdvEOImpl;


/**
 * Controller for ...
 */
public class xxierpsalaryadvCO extends OAControllerImpl {
    public static final String RCS_ID = "$Header$";
    public static final boolean RCS_ID_RECORDED = 
        VersionInfo.recordClassVersion(RCS_ID, "%packagename%");
  //  public CSSStyle txtUpperCase;
    /**
     * Layout and page setup logic for a region.
     * @param pageContext the current OA page context
     * @param webBean the web bean corresponding to the region
     */
    public void processRequest(OAPageContext pageContext, OAWebBean webBean) {
        super.processRequest(pageContext, webBean);
        OAApplicationModule am = pageContext.getApplicationModule(webBean);
//        txtUpperCase = new CSSStyle();
//               txtUpperCase.setProperty("text-transform","uppercase");
//               OAMessageTextInputBean txtbean=(OAMessageTextInputBean)webBean.findChildRecursive("RequestReason");
//               if (txtbean != null)
//               txtbean.setInlineStyle(txtUpperCase);
//         try {
//                 String jScript = "javascript:calcInstallment(this.form); " +
//                 " function calcInstallment(f) { if( document.getElementById('AdvanceAmount').value > document.getElementById('hdnBasicSalary').value) { alert('Salary Advance Amount Should be less than Basic Salary');  document.getElementById('AdvanceAmount').value='';document.getElementById('AdvanceAmount').focus();} }";
//                 OAMessageTextInputBean txtAdvAmt = (OAMessageTextInputBean)webBean.findChildRecursive("AdvanceAmount");
//                 OAMessageTextInputBean txtBasic = (OAMessageTextInputBean)webBean.findChildRecursive("hdnBasicSalary");
//              if(txtAdvAmt != null)
//               txtAdvAmt.setOnChange(jScript);
//             }catch(Exception e) {
//             throw new OAException(e.getMessage());
//             }
               
       
            
            
        String strParamAction ="";
        if(pageContext.getParameter("xxierpParamAction")!=null)
          strParamAction = pageContext.getParameter("xxierpParamAction");
        String strParamReqNo ="";
        if(pageContext.getParameter("xxierpParamReqNo")!=null)
             strParamReqNo = pageContext.getParameter("xxierpParamReqNo");
        String strStatusId ="";
        if(pageContext.getParameter("xxierpParamStatusId")!=null)
        strStatusId = pageContext.getParameter("xxierpParamStatusId");
        String strPersonId ="";
        if(pageContext.getParameter("xxierpParamPersonId")!=null)
        strPersonId = pageContext.getParameter("xxierpParamPersonId");
        String strLoginEmpId ="";
        if(pageContext.getParameter("xxierpParamLoginEmpId")!=null)
        strLoginEmpId = pageContext.getParameter("xxierpParamLoginEmpId");
        String strStatusDesc ="";
        if(pageContext.getParameter("xxierpParamStatusDesc")!=null)
        strStatusDesc = pageContext.getParameter("xxierpParamStatusDesc");
        String strRecommenderEmpId ="";
        if(pageContext.getParameter("xxierpParamRecommenderId")!=null)
        strRecommenderEmpId = pageContext.getParameter("xxierpParamRecommenderId");
        String strApproverEmpId ="";
        if(pageContext.getParameter("xxierpParamApproverId")!=null)
        strApproverEmpId = pageContext.getParameter("xxierpParamApproverId");
        String strLoginUser = "";
        /*  if(strLoginEmpId.equalsIgnoreCase(strPersonId))
                strLoginUser="REQUESTER";
            else if(strLoginEmpId.equalsIgnoreCase(strPersonId))
                strLoginUser="RECOMMENDER";
            else if(strLoginEmpId.equalsIgnoreCase(strPersonId))
                strLoginUser="APPROVER";
                */
       // OAApplicationModule am = pageContext.getApplicationModule(webBean);
        if (strParamAction != null && strParamAction.equals("ViewRequest")) {
                   
            setPreviousSalaryAdvanceDetails(pageContext, webBean, strPersonId,strParamReqNo);
            
            Serializable setParamList[] = { strParamReqNo };
            am.invokeMethod("updateRequestMethod", setParamList);
            OAViewObject reqVO = 
                (OAViewObject)am.findViewObject("XxierpSalaryAdvVO1");
            Row row[] = reqVO.getAllRowsInRange();
            
            if(reqVO.getRowCount()!=0)
            {
            OADBTransaction txn = (OADBTransaction)am.getOADBTransaction();
            oracle.jbo.domain.Date now = txn.getCurrentDBDate();
            //java.text.SimpleDateFormat displayDateFormat = new java.text.SimpleDateFormat ("dd-MMM-yyyy");
            // String OracleDateForm = displayDateFormat.format(currentDate.dateValue());
            java.sql.Date currentDate = now.dateValue();
            
            if (row[0].getAttribute("SalAdvReqDate") != null || 
                !row[0].getAttribute("SalAdvReqDate").toString().equals(""))
                 {
                   Date  cDate= (Date)   row[0].getAttribute("SalAdvReqDate");
                    currentDate=cDate.dateValue();
                 }
                 
            Number noOfInst= (Number)   row[0].getAttribute("NoOfInstalments");
            OAMessageTextInputBean NoOfInstalments = 
                (OAMessageTextInputBean)webBean.findChildRecursive("NoOfInstalments");
            if (noOfInst != null && !(noOfInst.toString().equals("")))
                NoOfInstalments.setValue(pageContext, noOfInst);
            else
                NoOfInstalments.setValue(pageContext, 3);

            String strRecommenderId = "";
            String strApproverId = "";
            if (!strStatusId.equalsIgnoreCase("SA01")) {
//                OAHeaderBean RequesterButtonRN = 
//                    (OAHeaderBean)webBean.findChildRecursive("RequesterButtonRN");
//                RequesterButtonRN.setRendered(false);
                OASubmitButtonBean btnSave = 
                     (OASubmitButtonBean)webBean.findChildRecursive("btnSave");
                 btnSave.setRendered(false);
                OASubmitButtonBean btnSubmit = 
                     (OASubmitButtonBean)webBean.findChildRecursive("btnSubmit");
                 btnSubmit.setRendered(false);
                OAMessageTextInputBean AdvanceAmount = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("AdvanceAmount");
                AdvanceAmount.setReadOnly(true);
                AdvanceAmount.setCSSClass("OraDataText");
                OAMessageTextInputBean RequestReason = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("RequestReason");
                RequestReason.setReadOnly(true);
                RequestReason.setCSSClass("OraDataText");
            }
                      

            strRecommenderId = 
                    setRequesterDetails(pageContext, webBean, strPersonId, 
                                        currentDate, strStatusId, 
                                        strStatusDesc);   
            if (strLoginEmpId.equalsIgnoreCase(strRecommenderEmpId) || 
                strLoginEmpId.equalsIgnoreCase(strApproverEmpId)) {
                OAHeaderBean RecommenderRN = 
                    (OAHeaderBean)webBean.findChildRecursive("RecommenderRN");
                RecommenderRN.setRendered(true);
                               
                Date  cDate= (Date)   row[0].getAttribute("RecommendDate");
                if (cDate != null && !(cDate.toString().equals("")))
                    {
                      //Date  cDate= (Date)   row[0].getAttribute("RecommendDate");
                       currentDate=cDate.dateValue();
                    }
                
                if (strStatusId.equalsIgnoreCase("SA02") && 
                    strLoginEmpId.equalsIgnoreCase(strRecommenderId)) {
                     OASubmitButtonBean btnRecommend = 
                          (OASubmitButtonBean)webBean.findChildRecursive("btnRecommend");
                      btnRecommend.setRendered(true);
                     OASubmitButtonBean btnRecommendReject = 
                          (OASubmitButtonBean)webBean.findChildRecursive("btnRecommendReject");
                      btnRecommendReject.setRendered(true);
                    
                    OAMessageTextInputBean RecommendReason = 
                        (OAMessageTextInputBean)webBean.findChildRecursive("RecommendReason");
                    RecommendReason.setReadOnly(false);
                    RecommendReason.setCSSClass("");
                    currentDate = now.dateValue();
                   }
                strApproverId = 
                        setRecommenderDetails(pageContext, webBean, strRecommenderId, 
                                              currentDate);
            }
            if (strLoginEmpId.equalsIgnoreCase(strApproverEmpId)) {
                OAHeaderBean ApproverRN = 
                    (OAHeaderBean)webBean.findChildRecursive("ApproverRN");
                ApproverRN.setRendered(true);
                               
                Date  cDate= (Date)   row[0].getAttribute("ApprovedDate");
                if (cDate != null && !(cDate.toString().equals("")))
                    {
                 // Date  cDate= (Date)   row[0].getAttribute("ApprovedDate");
                   currentDate=cDate.dateValue();
                }
                if (strStatusId.equalsIgnoreCase("SA03")) {
                     OASubmitButtonBean btnApprove = 
                          (OASubmitButtonBean)webBean.findChildRecursive("btnApprove");
                      btnApprove.setRendered(true);
                     OASubmitButtonBean btnApproverReject = 
                          (OASubmitButtonBean)webBean.findChildRecursive("btnApproverReject");
                      btnApproverReject.setRendered(true);
                    OAMessageTextInputBean ApproverReason = 
                        (OAMessageTextInputBean)webBean.findChildRecursive("ApproverReason");
                    ApproverReason.setReadOnly(false);
                    ApproverReason.setCSSClass("");
                    currentDate = now.dateValue();
                   
                }
                setApproverDetails(pageContext, webBean, strApproverId, 
                                   currentDate);
            }
            }
            else {
                OAException successMessage = 
                              new OAException("Request Details Not Available.", 
                                              OAException.ERROR);
                          pageContext.putDialogMessage(successMessage);
            }
        } else {
        
            setPreviousSalaryAdvanceDetails(pageContext, webBean, strLoginEmpId,"0");
            am.invokeMethod("createRequestMethod");
            OADBTransaction txn = (OADBTransaction)am.getOADBTransaction();
            oracle.jbo.domain.Date now = txn.getCurrentDBDate();
            //java.text.SimpleDateFormat displayDateFormat = new java.text.SimpleDateFormat ("dd-MMM-yyyy");
            // String OracleDateForm = displayDateFormat.format(currentDate.dateValue());
            java.sql.Date currentDate = now.dateValue();
          
            OAMessageTextInputBean NoOfInstalments = 
                (OAMessageTextInputBean)webBean.findChildRecursive("NoOfInstalments");
            NoOfInstalments.setValue(pageContext, 3);
            setRequesterDetails(pageContext, webBean, strLoginEmpId, 
                                currentDate, "SA01", strStatusDesc);      
                                            
        }
    }

    /**
     * Procedure to handle form submissions for form elements in
     * a region.
     * @param pageContext the current OA page context
     * @param webBean the web bean corresponding to the region
     */
    public void processFormRequest(OAPageContext pageContext, 
                                   OAWebBean webBean) {
        super.processFormRequest(pageContext, webBean);
        OAApplicationModule am = pageContext.getApplicationModule(webBean);
        
        if (pageContext.getParameter("event").equalsIgnoreCase("SaveRequest")) {
            setStatusDetails(pageContext, webBean, "SA01");
            
            am.invokeMethod("apply");
            OAException successMessage = 
                                      new OAException("Salary Advance Request Saved Successfully.", 
                                                      OAException.CONFIRMATION);
                                  pageContext.putDialogMessage(successMessage);
        } else if (pageContext.getParameter("event").equalsIgnoreCase("SubmitRequest")) {
            setStatusDetails(pageContext, webBean, "SA02");
            am.invokeMethod("apply");
            OAException successMessage = 
                                      new OAException("Salary Advance Request Submitted Successfully.", 
                                                      OAException.CONFIRMATION);
                                  pageContext.putDialogMessage(successMessage);
        } else if (pageContext.getParameter("event").equalsIgnoreCase("RecommendRequest")) {
            setStatusDetails(pageContext, webBean, "SA03");
            am.invokeMethod("apply");
            OAException successMessage = 
                                      new OAException("Salary Advance Request Recommended Successfully.", 
                                                      OAException.CONFIRMATION);
                                  pageContext.putDialogMessage(successMessage);
        }else if (pageContext.getParameter("event").equalsIgnoreCase("ApproveRequest")) {
            setStatusDetails(pageContext, webBean, "SA04");
            am.invokeMethod("apply");
            OAException successMessage = 
                                      new OAException("Salary Advance Request Approved Successfully.", 
                                                      OAException.CONFIRMATION);
                                  pageContext.putDialogMessage(successMessage);
        } 
        else if (pageContext.getParameter("event").equalsIgnoreCase("RecommenderReject") || 
                   pageContext.getParameter("event").equalsIgnoreCase("ApproverReject")) {
            setStatusDetails(pageContext, webBean, "SA05");
            am.invokeMethod("apply");
            OAException successMessage = 
                                      new OAException("Salary Advance Request Rejected.", 
                                                      OAException.CONFIRMATION);
                                  pageContext.putDialogMessage(successMessage);
        } 
       else if (pageContext.getParameter("event").equalsIgnoreCase("updateNoOfInstalments")
        || pageContext.getParameter("event").equalsIgnoreCase("updateAdvanceAmount")) {
            OAMessageTextInputBean BasicSalary = 
                (OAMessageTextInputBean)webBean.findChildRecursive("BasicSalary");
         
            //  Number bAmt=BasicSalary.getValue(pageContext).toString();
            double basic= Float.parseFloat(BasicSalary.getValue(pageContext).toString());
              
            OAMessageTextInputBean AdvanceAmount = 
                (OAMessageTextInputBean)webBean.findChildRecursive("AdvanceAmount");
          //  Number advAmt=AdvanceAmount.getValue(pageContext);
            double advAmt= Float.parseFloat(AdvanceAmount.getValue(pageContext).toString());
            
                            
            if(advAmt>basic)
            {
            OAException successMessage = 
                          new OAException("Salary Advance Amount Should be less than Basic Salary.", 
                                          OAException.ERROR);
                      pageContext.putDialogMessage(successMessage);
                AdvanceAmount.setValue(pageContext,"");
//            try {
//                    String jScript = "javascript:calcInstallment(this.form); " +
//                     " function calcInstallment(f) {  alert('Salary Advance Amount Should be less than Basic Salary');  document.getElementById('AdvanceAmount').value='';document.getElementById('AdvanceAmount').focus(); }";
//                        
//                      if(AdvanceAmount != null)
//                       AdvanceAmount.setAnchor(jScript);
//                     }catch(Exception e) {
//                     throw new OAException(e.getMessage());
//                     }
            }
            else
            {
                OAMessageTextInputBean NoOfInstalments = 
                (OAMessageTextInputBean)webBean.findChildRecursive("NoOfInstalments");
                double noOfInst= Float.parseFloat(NoOfInstalments.getValue(pageContext).toString());
              // Number noOfInst=(Number)NoOfInstalments.getValue(pageContext);
                
               DecimalFormat df = new DecimalFormat("###.##");
               double instAmt=advAmt/noOfInst;
              
                OAMessageTextInputBean InstalmentAmount = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("InstalmentAmount");
                InstalmentAmount.setValue(pageContext, df.format(instAmt));
              
               OAMessageTextInputBean OutStandingAmt = 
                   (OAMessageTextInputBean)webBean.findChildRecursive("OutStandingAmt");
               OutStandingAmt.setValue(pageContext,df.format(advAmt));
           }
          
        }
     else if (pageContext.getParameter("event").equalsIgnoreCase("CancelRequest")) {
                        pageContext.setForwardURL("OA.jsp?page=/xxhci/oracle/apps/XXIERP/SalaryAdvance/webui/xxierpsalaryadvSearchPG", 
                                                  null, 
                                                  OAWebBeanConstants.KEEP_MENU_CONTEXT, 
                                                  null, null, true, 
                                                  OAWebBeanConstants.ADD_BREAD_CRUMB_YES, 
                                                  OAWebBeanConstants.IGNORE_MESSAGES);
        }
    }


    /**
     * Procedure to Set Requester Details in the form.
     * @param pageContext the current OA page context
     * @param webBean the web bean corresponding to the region
     */
    public String setRequesterDetails(OAPageContext pageContext, 
                                      OAWebBean webBean, String PersonId, 
                                      java.sql.Date dt, String StatusId, 
                                      String StatusDesc) {
        if (StatusDesc == "" || StatusId == "SA01")
            StatusDesc = "New";
        OAApplicationModule am = pageContext.getApplicationModule(webBean);
        Serializable[] initParams = { PersonId, dt.toString() };
        am.invokeMethod("getEmployeesVO", initParams);
        OAViewObject empVO = (OAViewObject)am.findViewObject("EmpVO1");
        Row row[] = empVO.getAllRowsInRange();
        // To Display Items from EmpDetailsVO   
       

        if(empVO.getRowCount()!=0)
        {
        OAMessageTextInputBean Description = 
            (OAMessageTextInputBean)webBean.findChildRecursive("Description");
        Description.setValue(pageContext, StatusDesc);
        String strFullName = (String)row[0].getAttribute("FullName");
        OAMessageTextInputBean FullName = 
            (OAMessageTextInputBean)webBean.findChildRecursive("FullName");
        FullName.setValue(pageContext, strFullName);
        String strDName = (String)row[0].getAttribute("DName");
        OAMessageTextInputBean DName = 
            (OAMessageTextInputBean)webBean.findChildRecursive("DName");
        DName.setValue(pageContext, strDName);
        OAMessageTextInputBean sPersonId = 
            (OAMessageTextInputBean)webBean.findChildRecursive("PersonId");
        sPersonId.setValue(pageContext, PersonId);
        Number PapEmpServicePeriod = 
            (Number)row[0].getAttribute("PapEmpServicePeriod");
        OAMessageTextInputBean EmpServicePeriod = 
            (OAMessageTextInputBean)webBean.findChildRecursive("EmpServicePeriod");
        EmpServicePeriod.setValue(pageContext, PapEmpServicePeriod);


        OAMessageDateFieldBean SalAdvReqDate = 
            (OAMessageDateFieldBean)webBean.findChildRecursive("SalAdvReqDate");
        SalAdvReqDate.setValue(pageContext,dt);
        //Set Hidden Fields to save into salaryAdvance Table and Upadate salaryAdvanceVO       
        // Number PersonId = (Number)row[0].getAttribute("PersonId");
        OAMessageTextInputBean EmployeeNo = 
            (OAMessageTextInputBean)webBean.findChildRecursive("EmployeeNo");
        EmployeeNo.setValue(pageContext, PersonId);
        Number ReqSupervisorId = (Number)row[0].getAttribute("SupervisorId");
        OAMessageTextInputBean RecommendEmployeeId = 
            (OAMessageTextInputBean)webBean.findChildRecursive("RecommendEmployeeId");
        RecommendEmployeeId.setValue(pageContext, ReqSupervisorId);
        String BasicSal = (String)row[0].getAttribute("BasicSalary");
        OAMessageTextInputBean BasicSalary = 
            (OAMessageTextInputBean)webBean.findChildRecursive("BasicSalary");
        BasicSalary.setValue(pageContext, BasicSal);
        Number DId = (Number)row[0].getAttribute("DId");
        OAMessageTextInputBean EmpDeptId = 
            (OAMessageTextInputBean)webBean.findChildRecursive("EmpDeptId");
        EmpDeptId.setValue(pageContext, DId);
        // String LookupCode = (String)row[i].getAttribute("LookupCode");
        OAMessageTextInputBean StatusID = 
            (OAMessageTextInputBean)webBean.findChildRecursive("StatusId");
        StatusID.setValue(pageContext, StatusId);
        return ReqSupervisorId.toString();
          }
          else {
              OAException successMessage = 
                                       new OAException("Requester Details Not Available.", 
                                                       OAException.ERROR);
                                   pageContext.putDialogMessage(successMessage);
          }
       return "0";
    }

    /**
     *Procedure to Set Recommender Details in the form.
     * @param pageContext the current OA page context
     * @param webBean the web bean corresponding to the region
     */
    public String setRecommenderDetails(OAPageContext pageContext, 
                                        OAWebBean webBean, String PersonId, 
                                        java.sql.Date dt) {
        OAApplicationModule am = pageContext.getApplicationModule(webBean);
        Serializable[] initParams = { PersonId, dt.toString() };
        am.invokeMethod("getEmployeesVO", initParams);
        OAViewObject empVO = (OAViewObject)am.findViewObject("EmpVO1");
        Row row[] = empVO.getAllRowsInRange();
        if(empVO.getRowCount()!=0)
        {
        OAMessageTextInputBean RecommenderId = 
            (OAMessageTextInputBean)webBean.findChildRecursive("RecommenderId");
        RecommenderId.setValue(pageContext, PersonId);
        // Number ApproverId = (Number)row[i].getAttribute("PersonId");
        OAMessageTextInputBean RecommendEmployeeId = 
            (OAMessageTextInputBean)webBean.findChildRecursive("RecommendEmployeeId");
        // ApproverEmployeeId.setValue(pageContext, ApproverId);
        RecommendEmployeeId.setValue(pageContext, PersonId);
        String FullName = (String)row[0].getAttribute("FullName");
        OAMessageTextInputBean RecommenderName = 
            (OAMessageTextInputBean)webBean.findChildRecursive("RecommenderName");
        RecommenderName.setValue(pageContext, FullName);
        OAMessageDateFieldBean RecommendDate = 
            (OAMessageDateFieldBean)webBean.findChildRecursive("RecommendDate");
        RecommendDate.setValue(pageContext,dt);
        Number ReqSupervisorId = (Number)row[0].getAttribute("SupervisorId");
        OAMessageTextInputBean ApproverEmployeeId = 
            (OAMessageTextInputBean)webBean.findChildRecursive("ApproverEmployeeId");
        ApproverEmployeeId.setValue(pageContext, ReqSupervisorId);
        return ReqSupervisorId.toString();
        }
        else {
            OAException successMessage = 
                                     new OAException("Recommender Details Not Available.", 
                                                     OAException.ERROR);
                                 pageContext.putDialogMessage(successMessage);
        }
        return "0";
    }

    /**
     * Procedure to Set Approver Details in the form.
     * @param pageContext the current OA page context
     * @param webBean the web bean corresponding to the region
     */
    public void setApproverDetails(OAPageContext pageContext, 
                                   OAWebBean webBean, String PersonId, 
                                   java.sql.Date dt) {
        OAApplicationModule am = pageContext.getApplicationModule(webBean);
        Serializable[] initParams = { PersonId, dt.toString() };
        am.invokeMethod("getEmployeesVO", initParams);
        OAViewObject empVO = (OAViewObject)am.findViewObject("EmpVO1");
        Row row[] = empVO.getAllRowsInRange();
        // Number ApproverId = (Number)row[0].getAttribute("PersonId");
         if(empVO.getRowCount()!=0)
         {
        OAMessageTextInputBean ApproverEmployeeId = 
            (OAMessageTextInputBean)webBean.findChildRecursive("ApproverEmployeeId");
        // ApproverEmployeeId.setValue(pageContext, ApproverId);
        ApproverEmployeeId.setValue(pageContext, PersonId);
        OAMessageTextInputBean ApproverId = 
            (OAMessageTextInputBean)webBean.findChildRecursive("ApproverId");
        // ApproverEmployeeId.setValue(pageContext, ApproverId);
        ApproverId.setValue(pageContext, PersonId);
        String FullName = (String)row[0].getAttribute("FullName");
        OAMessageTextInputBean ApproverName = 
            (OAMessageTextInputBean)webBean.findChildRecursive("ApproverName");
        ApproverName.setValue(pageContext, FullName);
        OAMessageDateFieldBean ApprovedDate = 
            (OAMessageDateFieldBean)webBean.findChildRecursive("ApprovedDate");
        ApprovedDate.setValue(pageContext, dt);
         }
        else {
            OAException successMessage = 
                                     new OAException("Approver Details Not Available.", 
                                                     OAException.ERROR);
                                 pageContext.putDialogMessage(successMessage);
        }
        
    }

    /**
     * Procedure to update StatusID for the Event.
     * @param pageContext the current OA page context
     * @param webBean the web bean corresponding to the region
     */
    public void setStatusDetails(OAPageContext pageContext, OAWebBean webBean, 
                                 String Status) {
        OAMessageTextInputBean StatusId = 
            (OAMessageTextInputBean)webBean.findChildRecursive("StatusId");
        StatusId.setValue(pageContext, Status);
    }
    
    public void setPreviousSalaryAdvanceDetails(OAPageContext pageContext, 
                                      OAWebBean webBean, String PersonId, 
                                      String SeqNo) {      
        OAApplicationModule am = pageContext.getApplicationModule(webBean);
        Serializable[] initParams = { PersonId, SeqNo };
        am.invokeMethod("getPreviousSARequest", initParams);
        OAViewObject saVO = (OAViewObject)am.findViewObject("XxierpSalaryAdvVO1");
        Row row[] = saVO.getAllRowsInRange();
        // To Display Items from EmpDetailsVO    
        if(saVO.getRowCount()!=0)
        {
        String strReqNo = (String)row[0].getAttribute("SalAdvReqNo");
        OAMessageTextInputBean PrevRequestNo = 
            (OAMessageTextInputBean)webBean.findChildRecursive("PrevRequestNo");
        PrevRequestNo.setValue(pageContext, strReqNo);
        java.sql.Date strRequestDate = (java.sql.Date)row[0].getAttribute("SalAdvReqDate");
        OAMessageDateFieldBean PrevRequestDate = 
            (OAMessageDateFieldBean)webBean.findChildRecursive("PrevRequestDate");
        PrevRequestDate.setValue(pageContext, strRequestDate);
        Number strAdvanceAmount = (Number)row[0].getAttribute("AdvanceAmount");
        OAMessageTextInputBean PrevSalAdvance = 
            (OAMessageTextInputBean)webBean.findChildRecursive("PrevSalAdvance");
        PrevSalAdvance.setValue(pageContext, strAdvanceAmount);
        Number strInstalmentAmount = (Number)row[0].getAttribute("InstalmentAmount");
        OAMessageTextInputBean PrevInstallment = 
            (OAMessageTextInputBean)webBean.findChildRecursive("PrevInstallment");
        PrevInstallment.setValue(pageContext, strInstalmentAmount);  
        }
    }
}
